package net.chathu.airgw.packets.gw.clientpackets 
{
	import net.chathu.airgw.Config;
	import net.chathu.airgw.packets.gw.serverpackets.EchoPacket;

	/**
	 * ...
	 * @author ze
	 */
	public class CMDUser extends IRCReceivablePacket 
	{
		
		public function CMDUser() 
		{
			
		}
		
		override public function execute():void {
			if (Config.DEBUG)
			{
				sendToClient(new EchoPacket(Config.GW_ECHO_NICK, "Debug: " + data.join(" ")));
			}
			
			if (!sessionData.userReceived)
			{
				//ha alternativ logint akar a user, allitsuk at a username-t
				if (data.join(" ").indexOf("gwal") > 0) //egyelore jo lesz igy is..
				{
					sessionData.alternativeLogin = true;
					//alternativ login:
					var alternativeUserName:String = decodeURIComponent(data[1]);
					sessionData.soul.accountData.username = alternativeUserName;
					sendToClient(new EchoPacket(Config.GW_ECHO_NICK, "Alternatív belépés, username: " + alternativeUserName));
				}
				
				//ha van mar nick is, akkor mehet a login
				if (sessionData.nickReceived)
				{
					sessionData.soul.webLogin();
				} else {
					sendToClient(new EchoPacket(Config.GW_ECHO_NICK, "Waiting for nick"));
				}
			}
			sessionData.userReceived = true;
			
		}
		
		public static function getShortUsageDescription():String {
			return "User beállítás";
		}
		
		public static function getUsageDescription():String {
			return "Példa:\n" +
				"/user gipsz_jakab\n\n" +
				"Eredmény:\n" +
				"Debug: USER gipsz_jakab";
		}
	}

}